package com.gewu.ordlelist.base;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.transition.ChangeBounds;
import android.transition.Fade;
import android.transition.Slide;
import android.view.MenuItem;
import android.view.Window;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;

import com.gewu.ordlelist.utils.actionUpdate;


public abstract class BaseActivity extends AppCompatActivity {

    @SuppressLint("InlinedApi")
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        super.onCreate(savedInstanceState);
        setContentView(FindLayout());
        initview();
        isShowBackToolBar(isShowBackToolbar());
    }

    /**
     * 加载布局
     * @return
     */
    public abstract int FindLayout();

    /**
     * 获取顶部bar
     *
     * @return
     */
    public abstract Toolbar getToolBar();

    /**
     * 设置顶部bar返回
     */
    public abstract boolean isShowBackToolbar();

    /**
     * 设置toolbar的标题
     * @return
     */
    public abstract String setToolbarText();

    /**
     * toolbar的返回
     * @param flage
     */
    public void isShowBackToolBar(boolean flage){
        if (!flage){
            return;
        }
        setSupportActionBar(getToolBar());
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @SuppressLint("NewApi")
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finishAfterTransition();
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    public abstract void initview();

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        ActivityCompat.finishAfterTransition(this);
    }


}
